package com.example.myapplication.part03.part15;


import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.example.myapplication.R;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ViewlistActivity extends AppCompatActivity {
    private ViewPager viewPager;
    private List<View> views = new ArrayList<>();
    private List<File> files = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main015);

        viewPager = findViewById(R.id.viewPager);

        // 初始化ViewPager的页面
        View view0 = getLayoutInflater().inflate(R.layout.listview, null);
        View view1 = getLayoutInflater().inflate(R.layout.listview, null);
        View view2 = getLayoutInflater().inflate(R.layout.listview, null);
        views.add(view0);
        views.add(view1);
        views.add(view2);
        viewPager.setAdapter(new PageViewAdapter(views));

        // 初始化ListView的数据
        files.add(new File("项目一"));
        files.add(new File("项目二"));
        files.add(new File("项目三"));
        files.add(new File("项目四"));


        // 设置每个ListView的适配器
        setupListView(view0, "子界面一");
        setupListView(view1, "子界面二");
        setupListView(view2, "子界面三");
    }

    private void setupListView(View view, String title) {
        // 设置标题
        TextView textView = view.findViewById(R.id.title);
        textView.setText(title);

        // 设置ListView的适配器
        ListView listView = view.findViewById(R.id.listview_phone);
        listView.setVisibility(View.VISIBLE);
        listView.setAdapter(new ListViewAdapter(files, getLayoutInflater()));
    }
}
